package org.clxmm.security.springmvc.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

/**
 * @author clxmm
 * @Description 相当于 springmvc.xml
 * @create 2021-06-06 5:11 下午
 */
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "org.clxmm.security.springmvc",
        includeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION, value =
                Controller.class)}
)
public class WebConfig implements WebMvcConfigurer {

    //视频解析器

    @Bean
    public InternalResourceViewResolver viewResolver() {
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setPrefix("/WEB‐INF/views/");
        viewResolver.setSuffix(".jsp");
        return viewResolver;

    }


    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        // 在WebConfig.java中添加默认请求根路径跳转到/login，此url为spring security提供:
        registry.addViewController("/").setViewName("redirect:login");
    }


}
